//go:build darwin || linux
// +build darwin linux

package utils

import (
	"runtime"
	"syscall"
)

// AvailableDIskSize 获取磁盘剩余空间大小
func AvailableDIskSize() (uint64, error) {
	wd, err := syscall.Getwd()
	if err != nil {
		return 0, err
	}
	if runtime.GOOS == "windows" {
		return 0, nil
	} else {
		var stat syscall.Statfs_t
		if err := syscall.Statfs(wd, &stat); err != nil {
			return 0, err
		}

		return stat.Bavail * uint64(stat.Bsize), nil
	}
}
